import collections
class Solution(object):
    def distinctNames(self, ideas):
        d = collections.defaultdict(set)
        list_d = collections.defaultdict(list)
        t = collections.defaultdict(int)
        jiaocha = collections.defaultdict(int)
        total = {i for i in range(26)}
        for name in ideas:
            suf = name[1:]
            pre = ord(name[0]) - ord('a')
            d[suf].add(pre)
            list_d[suf].append(pre)
            t[pre] += 1
        for suf in list_d:
            l = list_d[suf]
            m = len(l)
            for i in range(m):
                for j in range(i + 1, m):
                    jiaocha[(l[i], l[j])] += 1
                    jiaocha[(l[j], l[i])] += 1
        ans = 0
        for suf in d:
            another_set = total - d[suf]
            for u in d[suf]:
                for v in another_set:
                    ans += t[v] - jiaocha[(u, v)]
        return ans

data = Solution()
ideas = ["coffee","donuts","time","toffee"]
print(data.distinctNames(ideas))